/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.settlement.entity.customersettlement;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.modules.base.entity.customer.Customer;
import com.jeesite.modules.order.entity.serviceorder.ServiceOrder;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * 客户结算单Entity
 * @author Kilo
 * @version 2021-03-10
 */
@Table(name="t_customer_settlement", alias="a", columns={
		@Column(name="customer_settlement_id", attrName="customerSettlementId", label="客户结算单ID", isPK=true),
		@Column(name="customer_settlement_code", attrName="customerSettlementCode", label="客户结算单编号"),
		@Column(name="customer_id", attrName="customerId", label="客户"),
		@Column(name="invoice_customer_id", attrName="invoiceCustomerId", label="开票客户"),
		@Column(name="date", attrName="date", label="结算日期"),
		@Column(name="service_order_id", attrName="serviceOrderId", label="服务订单"),
		@Column(name="supply_chain_service_agreement_id", attrName="supplyChainServiceAgreementId", label="供应链服务协议"),
		@Column(name="letter_credit_code", attrName="letterCreditCode", label="信用证"),
		@Column(name="payment_method", attrName="paymentMethod", label="付款方式"),
		@Column(name="finish_flag", attrName="finishFlag", label="是否结算完结"),
		@Column(name="customer_prepayment_balance", attrName="customerPrepaymentBalance", label="客户预收款余额", isQuery=false),
		@Column(name="order_prepayment_balance", attrName="orderPrepaymentBalance", label="订单预收款余额", isQuery=false),
		@Column(name="create_by", attrName="createBy", label="创建者", isUpdate=false),
		@Column(name="create_date", attrName="createDate", label="创建时间", isUpdate=false),
		@Column(name="update_by", attrName="updateBy", label="更新者", isQuery=false),
		@Column(name="update_date", attrName="updateDate", label="更新时间", isQuery=false),
		@Column(name="remarks", attrName="remarks", label="备注信息", isQuery=false),
	}, joinTable={
		@JoinTable(type=Type.LEFT_JOIN, entity= Customer.class, attrName="customer", alias="c",
				on="c.customer_id = a.customer_id", columns={
				@Column(name="customer_id", label="客户编码", isPK=true),
				@Column(name="customer_name", label="客户名称", isQuery=false),
		}),
		@JoinTable(type=Type.LEFT_JOIN, entity= Customer.class, attrName="invoiceCustomer", alias="d",
				on="d.customer_id = a.invoice_customer_id", columns={
				@Column(name="customer_id", label="开票客户编码", isPK=true),
				@Column(name="customer_name", label="开票客户名称", isQuery=false),
		}),
		@JoinTable(type=Type.LEFT_JOIN, entity= ServiceOrder.class, attrName="serviceOrder", alias="e",
				on="e.service_order_id = a.service_order_id", columns={
				@Column(name="service_order_id", label="服务订单ID", isPK=true),
				@Column(name="service_order_code", label="服务订单编号", isQuery=false),
		}),
},orderBy="a.update_date DESC"
)
public class CustomerSettlement extends DataEntity<CustomerSettlement> {
	
	private static final long serialVersionUID = 1L;
	private String customerSettlementId;		// 客户结算单ID
	private String customerSettlementCode;		// 客户结算单编号
	private String customerId;		// 客户
	private String invoiceCustomerId;		// 开票客户
	private Date date;		// 结算日期
	private String serviceOrderId;		// 服务订单
	private String supplyChainServiceAgreementId;		// 供应链服务协议
	private String letterCreditCode;		// 信用证
	private String paymentMethod;		// 付款方式
	private String finishFlag;		// 是否结算完结
	private Double customerPrepaymentBalance;		// 客户预收款余额
	private Double orderPrepaymentBalance;		// 订单预收款余额
	private List<CustomerSettlementPayment> customerSettlementPaymentList = ListUtils.newArrayList();		// 子表列表
	private List<CustomerSettlementPrepayment> customerSettlementPrepaymentList = ListUtils.newArrayList();		// 子表列表
	private List<CustomerSettlementDetail> customerSettlementDetailList = ListUtils.newArrayList();		// 子表列表
	private Customer customer;
	private Customer invoiceCustomer;
    private ServiceOrder serviceOrder;

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Customer getInvoiceCustomer() {
		return invoiceCustomer;
	}

	public void setInvoiceCustomer(Customer invoiceCustomer) {
		this.invoiceCustomer = invoiceCustomer;
	}

	public CustomerSettlement() {
		this(null);
	}

	public CustomerSettlement(String id){
		super(id);
	}
	
	public String getCustomerSettlementId() {
		return customerSettlementId;
	}

	public void setCustomerSettlementId(String customerSettlementId) {
		this.customerSettlementId = customerSettlementId;
	}
	
	@Length(min=0, max=64, message="客户长度不能超过 64 个字符")
	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}
	
	@Length(min=0, max=64, message="开票客户长度不能超过 64 个字符")
	public String getInvoiceCustomerId() {
		return invoiceCustomerId;
	}

	public void setInvoiceCustomerId(String invoiceCustomerId) {
		this.invoiceCustomerId = invoiceCustomerId;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@NotNull(message="结算日期不能为空")
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@Length(min=0, max=64, message="服务订单长度不能超过 64 个字符")
	public String getServiceOrderId() {
		return serviceOrderId;
	}

	public void setServiceOrderId(String serviceOrderId) {
		this.serviceOrderId = serviceOrderId;
	}
	
	@Length(min=0, max=64, message="供应链服务协议长度不能超过 64 个字符")
	public String getSupplyChainServiceAgreementId() {
		return supplyChainServiceAgreementId;
	}

	public void setSupplyChainServiceAgreementId(String supplyChainServiceAgreementId) {
		this.supplyChainServiceAgreementId = supplyChainServiceAgreementId;
	}
	
	@Length(min=0, max=100, message="信用证长度不能超过 100 个字符")
	public String getLetterCreditCode() {
		return letterCreditCode;
	}

	public void setLetterCreditCode(String letterCreditCode) {
		this.letterCreditCode = letterCreditCode;
	}
	
	@Length(min=0, max=2, message="付款方式长度不能超过 2 个字符")
	public String getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(String paymentMethod) {
		this.paymentMethod = paymentMethod;
	}
	
	@Length(min=0, max=2, message="是否结算完结长度不能超过 2 个字符")
	public String getFinishFlag() {
		return finishFlag;
	}

	public void setFinishFlag(String finishFlag) {
		this.finishFlag = finishFlag;
	}
	
	public Double getCustomerPrepaymentBalance() {
		return customerPrepaymentBalance;
	}

	public void setCustomerPrepaymentBalance(Double customerPrepaymentBalance) {
		this.customerPrepaymentBalance = customerPrepaymentBalance;
	}
	
	public Double getOrderPrepaymentBalance() {
		return orderPrepaymentBalance;
	}

	public void setOrderPrepaymentBalance(Double orderPrepaymentBalance) {
		this.orderPrepaymentBalance = orderPrepaymentBalance;
	}
	
	public Date getDate_gte() {
		return sqlMap.getWhere().getValue("date", QueryType.GTE);
	}

	public void setDate_gte(Date date) {
		sqlMap.getWhere().and("date", QueryType.GTE, date);
	}
	
	public Date getDate_lte() {
		return sqlMap.getWhere().getValue("date", QueryType.LTE);
	}

	public void setDate_lte(Date date) {
		sqlMap.getWhere().and("date", QueryType.LTE, date);
	}
	
	public Date getCreateDate_gte() {
		return sqlMap.getWhere().getValue("create_date", QueryType.GTE);
	}

	public void setCreateDate_gte(Date createDate) {
		sqlMap.getWhere().and("create_date", QueryType.GTE, createDate);
	}
	
	public Date getCreateDate_lte() {
		return sqlMap.getWhere().getValue("create_date", QueryType.LTE);
	}

	public void setCreateDate_lte(Date createDate) {
		sqlMap.getWhere().and("create_date", QueryType.LTE, createDate);
	}
	
	public List<CustomerSettlementPayment> getCustomerSettlementPaymentList() {
		return customerSettlementPaymentList;
	}

	public void setCustomerSettlementPaymentList(List<CustomerSettlementPayment> customerSettlementPaymentList) {
		this.customerSettlementPaymentList = customerSettlementPaymentList;
	}
	
	public List<CustomerSettlementPrepayment> getCustomerSettlementPrepaymentList() {
		return customerSettlementPrepaymentList;
	}

	public void setCustomerSettlementPrepaymentList(List<CustomerSettlementPrepayment> customerSettlementPrepaymentList) {
		this.customerSettlementPrepaymentList = customerSettlementPrepaymentList;
	}
	
	public List<CustomerSettlementDetail> getCustomerSettlementDetailList() {
		return customerSettlementDetailList;
	}

	public void setCustomerSettlementDetailList(List<CustomerSettlementDetail> customerSettlementDetailList) {
		this.customerSettlementDetailList = customerSettlementDetailList;
	}

    public ServiceOrder getServiceOrder() {
        return serviceOrder;
    }

    public void setServiceOrder(ServiceOrder serviceOrder) {
        this.serviceOrder = serviceOrder;
    }

    public String getCustomerSettlementCode() {
        return customerSettlementCode;
    }

    public void setCustomerSettlementCode(String customerSettlementCode) {
        this.customerSettlementCode = customerSettlementCode;
    }
}